﻿<UserControl x:Class="openPDC.UI.UserControls.DeviceUserControl"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" d:DesignHeight="650" d:DesignWidth="850"
             xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:uc="clr-namespace:GSF.TimeSeries.UI.UserControls;assembly=GSF.TimeSeries.UI.WPF"
             xmlns:tsfBinding="clr-namespace:GSF.TimeSeries.UI.Binding;assembly=GSF.TimeSeries.UI"
             Background="Transparent">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/GSF.TimeSeries.UI.WPF;Component/Resources/CommonResource.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <StackPanel Orientation="Vertical">

        <StackPanel.Resources>
            <CollectionViewSource Source="{Binding Path=NodeLookupList}" x:Key="NodeLookupList"/>
            <CollectionViewSource Source="{Binding Path=ConcentratorDeviceLookupList}" x:Key="ConcentratorDeviceLookupList"/>
            <CollectionViewSource Source="{Binding Path=CompanyLookupList}" x:Key="CompanyLookupList"/>
            <CollectionViewSource Source="{Binding Path=HistorianLookupList}" x:Key="HistorianLookupList"/>
            <CollectionViewSource Source="{Binding Path=InterconnectionLookupList}" x:Key="InterconnectionLookupList"/>
            <CollectionViewSource Source="{Binding Path=ProtocolLookupList}" x:Key="ProtocolLookupList"/>
            <CollectionViewSource Source="{Binding Path=VendorDeviceLookupList}" x:Key="VendorDeviceLookupList"/>
            <CollectionViewSource Source="{Binding Path=TimezoneLookupList}" x:Key="TimezoneLookupList"/>
        </StackPanel.Resources>

        <Grid x:Name="GridDetailView" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="5" DataContext="{Binding Path=CurrentItem, Mode=TwoWay}" DataContextChanged="GridDetailView_DataContextChanged">
            <Grid.BindingGroup >
                <BindingGroup Name="input"/>
            </Grid.BindingGroup>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            
            <!--First row-->
            <StackPanel Orientation="Horizontal" Grid.Column="0" Grid.ColumnSpan="4" HorizontalAlignment="Right">
                <Button Template="{StaticResource HyperlinkStyleButtonTemplate}" Content="Phasors" Command="{tsfBinding:GridButtonCommand Path=DataContext.PhasorCommand, RelativeSource={RelativeSource AncestorType=UserControl}}">
                    <Button.Visibility>
                        <Binding Path="DataContext.IsNewRecord" RelativeSource="{RelativeSource AncestorType=UserControl}" Converter="{StaticResource ObjectToVisibilityConverter}">
                            <Binding.ConverterParameter>
                                <sys:Boolean>True</sys:Boolean>
                            </Binding.ConverterParameter>
                        </Binding>
                    </Button.Visibility>
                </Button>
                <Button Template="{StaticResource HyperlinkStyleButtonTemplate}" Content="Measurements" Command="{tsfBinding:GridButtonCommand Path=DataContext.MeasurementCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" Width="Auto">
                    <Button.Visibility>
                        <Binding Path="DataContext.IsNewRecord" RelativeSource="{RelativeSource AncestorType=UserControl}" Converter="{StaticResource ObjectToVisibilityConverter}">
                            <Binding.ConverterParameter>
                                <sys:Boolean>True</sys:Boolean>
                            </Binding.ConverterParameter>
                        </Binding>
                    </Button.Visibility>
                </Button>
            </StackPanel>

            <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right">
                <TextBlock Text="Acronym" Style="{StaticResource RequiredLabel}" />
                <TextBlock Style="{StaticResource RequiredMarker}" />
            </StackPanel>
            <TextBox x:Name="TextBoxAcronym" Grid.Row="1" Grid.Column="1" Text="{tsfBinding:Column Path=Acronym}" CharacterCasing="Upper" MaxLength="50"/>

            <TextBlock Text="Concentrator" Grid.Row="1" Grid.Column="2" />
            <StackPanel Grid.Row="1" Grid.Column="3" Orientation="Horizontal">
                <ComboBox x:Name="ComboBoxConcentrator" ItemsSource="{Binding Source={StaticResource ConcentratorDeviceLookupList}}" DisplayMemberPath="Value"
                      SelectedItem="{tsfBinding:Column Path=ParentID, Converter={StaticResource DictionaryToKeyValuePairConverter}, ConverterParameter={StaticResource ConcentratorDeviceLookupList}}"
                      IsEnabled="{Binding ElementName=CheckBoxConcentrator, Path=IsChecked, Converter={StaticResource NotConverter}}"/>
                <Button ToolTip="View Concentrator Configuration" Width="Auto" Visibility="{Binding ElementName=ComboBoxConcentrator, Path=SelectedIndex, Converter={StaticResource ObjectToVisibilityConverter}}"
                        Command="{Binding Path=DataContext.ConfigureConcentratorCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=StackPanel, AncestorLevel=2}}">
                    <Button.Template>
                        <ControlTemplate>
                            <Image Source="/GSF.TimeSeries.UI;component/images/EditConfiguration.png" Height="16" Width="16" />
                        </ControlTemplate>
                    </Button.Template>
                </Button>
            </StackPanel>
            
            <TextBlock Text="Name" Grid.Row="2" Grid.Column="0"/>
            <TextBox Grid.Row="2" Grid.Column="1" Text="{tsfBinding:Column Path=Name}" MaxLength="100" />

            <TextBlock Text="Time Zone" Grid.Row="2" Grid.Column="2" />
            <ComboBox Grid.Row="2" Grid.Column="3" ItemsSource="{Binding Source={StaticResource TimezoneLookupList}}" DisplayMemberPath="Value"
                      SelectedItem="{tsfBinding:Column Path=TimeZone, Converter={StaticResource DictionaryToKeyValuePairConverter}, ConverterParameter={StaticResource TimezoneLookupList}}"/>

            <StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="0" HorizontalAlignment="Right">
                <TextBlock Text="ID Code (Access ID)" Style="{StaticResource RequiredLabel}" />
                <TextBlock Style="{StaticResource RequiredMarker}" />
            </StackPanel>
            <TextBox Grid.Row="3" Grid.Column="1" Text="{tsfBinding:Column Path=AccessID}" Width="{StaticResource XXSmallItemSize}"/>

            <TextBlock Text="Frames Per Second" Grid.Row="3" Grid.Column="2" />
            <TextBox Grid.Row="3" Grid.Column="3" Text="{tsfBinding:Column Path=FramesPerSecond}" Width="35" />

            <TextBlock Text="Company" Grid.Row="4" Grid.Column="0" />
            <ComboBox Grid.Row="4" Grid.Column="1" ItemsSource="{Binding Source={StaticResource CompanyLookupList}}" DisplayMemberPath="Value"
                      SelectedItem="{tsfBinding:Column Path=CompanyID, Converter={StaticResource DictionaryToKeyValuePairConverter}, ConverterParameter={StaticResource CompanyLookupList}}"/>

            <TextBlock Text="Historian" Grid.Row="4" Grid.Column="2" />
            <ComboBox Grid.Row="4" Grid.Column="3" ItemsSource="{Binding Source={StaticResource HistorianLookupList}}" DisplayMemberPath="Value"
                      SelectedItem="{tsfBinding:Column Path=HistorianID, Converter={StaticResource DictionaryToKeyValuePairConverter}, ConverterParameter={StaticResource HistorianLookupList}}"/>

            <TextBlock Text="Protocol" Grid.Row="5" Grid.Column="0" />
            <ComboBox Grid.Row="5" Grid.Column="1" ItemsSource="{Binding Source={StaticResource ProtocolLookupList}}" DisplayMemberPath="Value"
                      SelectedItem="{tsfBinding:Column Path=ProtocolID, Converter={StaticResource DictionaryToKeyValuePairConverter}, ConverterParameter={StaticResource ProtocolLookupList}}"/>

            <TextBlock Text="Device Vendor" Grid.Row="5" Grid.Column="2" />
            <ComboBox Grid.Row="5" Grid.Column="3" ItemsSource="{Binding Source={StaticResource VendorDeviceLookupList}}" DisplayMemberPath="Value"
                      SelectedItem="{tsfBinding:Column Path=VendorDeviceID, Converter={StaticResource DictionaryToKeyValuePairConverter}, ConverterParameter={StaticResource VendorDeviceLookupList}}"/>

            <TextBlock Text="Connection String" Grid.Row="6" Grid.Column="0" />
            <StackPanel Orientation="Horizontal" Grid.Row="6" Grid.Column="1">
                <TextBox Text="{tsfBinding:Column Path=ConnectionString}" Height="50" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"/>
                <Button Command="{Binding Path=DataContext.BuildConnectionStringCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=StackPanel, AncestorLevel=2}}"
                             VerticalAlignment="Top" ToolTip="Build connection string" Width="Auto">
                    <Button.Template>
                        <ControlTemplate>
                            <Image Source="/GSF.TimeSeries.UI;component/images/Plus.png" Height="24" Width="24" />
                        </ControlTemplate>
                    </Button.Template>
                </Button>
            </StackPanel>
            
            <TextBlock Text="Alternate Command Channel" Grid.Row="6" Grid.Column="2"/>
            <StackPanel Orientation="Horizontal" Grid.Row="6" Grid.Column="3">
                <TextBox Text="{tsfBinding:Column Path=AlternateCommandChannel}" Height="50" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"/>
                <Button Command="{Binding Path=DataContext.BuildAlternateCommandChannelCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=StackPanel, AncestorLevel=2}}"
                             VerticalAlignment="Top" ToolTip="Build alternate command channel" Width="Auto">
                    <Button.Template>
                        <ControlTemplate>
                            <Image Source="/GSF.TimeSeries.UI;component/images/Plus.png" Height="24" Width="24" />
                        </ControlTemplate>
                    </Button.Template>
                </Button>
            </StackPanel>            

            <StackPanel Orientation="Horizontal" Grid.Row="7" Grid.Column="0" HorizontalAlignment="Right">
                <TextBlock Text="Data Loss Interval" Style="{StaticResource RequiredLabel}" />
                <TextBlock Style="{StaticResource RequiredMarker}" />
            </StackPanel>
            <TextBox Grid.Row="7" Grid.Column="1" Text="{tsfBinding:Column Path=DataLossInterval}" MaxLength="50" Width="{StaticResource XSmallItemSize}"/>

            <StackPanel Orientation="Horizontal" Grid.Row="7" Grid.Column="2" HorizontalAlignment="Right">
                <TextBlock Text="Time Adjustment Ticks" Style="{StaticResource RequiredLabel}" />
                <TextBlock Style="{StaticResource RequiredMarker}" />
            </StackPanel>
            <TextBox Grid.Row="7" Grid.Column="3" Text="{tsfBinding:Column Path=TimeAdjustmentTicks}" MaxLength="50" Width="{StaticResource XSmallItemSize}"/>

            <StackPanel Orientation="Horizontal" Grid.Row="8" Grid.Column="0" HorizontalAlignment="Right">
                <TextBlock Text="Allowed Parsing Exception" Style="{StaticResource RequiredLabel}" />
                <TextBlock Style="{StaticResource RequiredMarker}" />
            </StackPanel>
            <TextBox Grid.Row="8" Grid.Column="1" Text="{tsfBinding:Column Path=AllowedParsingExceptions}" MaxLength="50" Width="35" />

            <StackPanel Orientation="Horizontal" Grid.Row="8" Grid.Column="2" HorizontalAlignment="Right">
                <TextBlock Text="Parsing Exception Window" Style="{StaticResource RequiredLabel}" />
                <TextBlock Style="{StaticResource RequiredMarker}" />
            </StackPanel>
            <TextBox Grid.Row="8" Grid.Column="3" Text="{tsfBinding:Column Path=ParsingExceptionWindow}" MaxLength="50" Width="{StaticResource XSmallItemSize}"/>

            <StackPanel Orientation="Horizontal" Grid.Row="9" Grid.Column="0" HorizontalAlignment="Right">
                <TextBlock Text="Delayed Connection Interval" Style="{StaticResource RequiredLabel}" TextWrapping="Wrap" />
                <TextBlock Style="{StaticResource RequiredMarker}" />
            </StackPanel>
            <TextBox Grid.Row="9" Grid.Column="1" Text="{tsfBinding:Column Path=DelayedConnectionInterval}" MaxLength="50" Width="{StaticResource XSmallItemSize}"/>

            <StackPanel Orientation="Horizontal" Grid.Row="9" Grid.Column="2" HorizontalAlignment="Right">
                <TextBlock Text="Measurement Reporting Interval" Style="{StaticResource RequiredLabel}" />
                <TextBlock Style="{StaticResource RequiredMarker}" />
            </StackPanel>
            <TextBox Grid.Row="9" Grid.Column="3" Text="{tsfBinding:Column Path=MeasurementReportingInterval}" MaxLength="50" Width="{StaticResource XXSmallItemSize}" />

            <TextBlock Text="Longitude" Grid.Row="10" Grid.Column="0"/>
            <TextBox Grid.Row="10" Grid.Column="1" Text="{tsfBinding:Column Path=Longitude}" />            

            <TextBlock Text="Latitude" Grid.Row="10" Grid.Column="2"/>
            <TextBox Grid.Row="10" Grid.Column="3" Text="{tsfBinding:Column Path=Latitude}" />
            
            <TextBlock Text="Interconnection" Grid.Row="11" Grid.Column="0" />
            <ComboBox Grid.Row="11" Grid.Column="1" ItemsSource="{Binding Source={StaticResource InterconnectionLookupList}}" DisplayMemberPath="Value"
                      SelectedItem="{tsfBinding:Column Path=InterconnectionID, Converter={StaticResource DictionaryToKeyValuePairConverter}, ConverterParameter={StaticResource InterconnectionLookupList}}"/>
            
            <StackPanel Orientation="Horizontal" Grid.Row="12" Grid.ColumnSpan="4">
                <CheckBox Content="Skip Disable Real-time Data" IsChecked="{tsfBinding:Column Path=SkipDisableRealTimeData}"/>
                <CheckBox Content="Allow Use Of Cached Configuration" IsChecked="{tsfBinding:Column Path=AllowUseOfCachedConfiguration}"/>
                <CheckBox Content="Auto Start Data Parsing Sequence" IsChecked="{tsfBinding:Column Path=AutoStartDataParsingSequence}"/>
                <CheckBox x:Name="CheckBoxConcentrator" Content="Concentrator" IsChecked="{tsfBinding:Column Path=IsConcentrator}"/>                
            </StackPanel>

            <TextBlock Text="Runtime ID" Grid.Row="13" Grid.Column="0" />
            <StackPanel Orientation="Horizontal" Grid.Row="13" Grid.Column="1">
                <TextBlock Text="{tsfBinding:Column Path=DataContext.RuntimeID, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl, AncestorLevel=1}}" />
                <Button Content="Initialize" Command="{Binding Path=DataContext.InitializeCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl, AncestorLevel=1}}" 
                        IsEnabled="{Binding Path=DataContext.IsNewRecord, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl, AncestorLevel=1}, Converter={StaticResource NotConverter}}"/>
            </StackPanel>

            <CheckBox Content="Connect On Demand" IsChecked="{tsfBinding:Column Path=ConnectOnDemand}" Grid.Row="13" Grid.Column="2"/>
            <CheckBox Content="Enabled" IsChecked="{tsfBinding:Column Path=Enabled}" Grid.Row="13" Grid.Column="3"/>

        </Grid>

        <uc:DetailViewFooterUserControl x:Name="UserControlDetailViewFooter" DeleteCommand="{Binding DeleteCommand}" ClearCommand="{Binding ClearCommand}" SaveCommand="{Binding SaveCommand}"
                SaveEnabled="{tsfBinding:DataOperation Path=(Validation.HasError)}" />
   
        <TextBlock Text="Concentrator Device List" FontWeight="Bold" HorizontalAlignment="Left" Visibility="{Binding Path=CurrentItem.IsConcentrator, Converter={StaticResource ObjectToVisibilityConverter}}"/>

        <sdk:DataGrid x:Name="DataGridList" ItemsSource="{tsfBinding:Column Path=PdcDevices}" SelectedItem="{Binding Path=CurrentItem, Mode=TwoWay}" 
                      Visibility="{Binding Path=CurrentItem.IsConcentrator, Converter={StaticResource ObjectToVisibilityConverter}}" Height="100">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Header="Acronym" Width="*" Binding="{tsfBinding:Column Path= Acronym}"/>
                <sdk:DataGridTextColumn Header="Name" Width="2*" Binding="{tsfBinding:Column Path= Name}" />                
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>

    </StackPanel>
</UserControl>
